package com.tanhua.app.controller;

import com.tanhua.app.interceptor.UserHolder;
import com.tanhua.app.service.TanhuaService;
import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest todayBest = tanhuaService.todayBest();
        return ResponseEntity.ok(todayBest);
    }

    //首页推荐
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto) {
        PageResult pageResult = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pageResult);
    }

    //查看佳人信息
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId ){
        TodayBest vo = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }

    //查询陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam Long userId){
        String question =  tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    //回复陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map){
        String strUserId = map.get("userId").toString();
        Long userId = Long.valueOf(strUserId);
        String reply = (String) map.get("reply");
        tanhuaService.replyStrangerQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    //探花功能 显示推荐用户
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> list = tanhuaService.cards(UserHolder.getUserId());
        return ResponseEntity.ok(list);
    }

    //喜欢功能
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long loveUserId){
        tanhuaService.love(UserHolder.getUserId(),loveUserId);
        return ResponseEntity.ok(null);
    }

    //不喜欢功能
    @GetMapping("/{id}/unlove")
    public ResponseEntity unLove(@PathVariable("id") Long loveUserId){
        tanhuaService.unLove(UserHolder.getUserId(),loveUserId);
        return ResponseEntity.ok(null);
    }

    //搜附近功能
   @GetMapping("/search")
    public ResponseEntity search(@RequestParam String gender,@RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> vos = tanhuaService.search(UserHolder.getUserId(),gender,distance);
        return ResponseEntity.ok(vos);
   }
}
